import Taro, { Component, Config } from '@tarojs/taro'
import './index.scss'

let livePlayer = Taro.requirePlugin('live-player-plugin')
export default class Index extends Component {
  state: any
  config: Config = {
    navigationStyle: 'custom',
    usingComponents: {
      'subscribe': 'plugin-private://wx2b03c6e691cd7370/components/subscribe/subscribe'
    }
  }

  constructor() {
    super(...arguments)
    this.state = {
      roomId: 1000,
      width: 750,
      height: 750,
      fontSize: 17,
      color: '#FFFFFF',
      // customParams: encodeURIComponent(JSON.stringify({ path: 'pages/index/index', pid: 1 })),
      backgroundColor: '#6467F0',
    }
  }

  componentDidMount () {
    // wx.navigateTo({
    //   url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=1`
    // })
    livePlayer.getLiveStatus({ room_id: 1 }).then(res => {
      console.log(res)
    }).catch(err => {
      console.log('get live status', err)
    })

    livePlayer.getSubscribeStatus({ room_id: 1 }).then(res => {
      console.log(res)
    }).catch(err => {
      console.log('get live status', err)
    })

    livePlayer.getOpenid({ room_id: 1 }).then(res => {
      console.log(res)
    }).catch(err => {
      console.log('get live status', err)
    })

    livePlayer.getShareParams({ room_id: 1 }).then(res => {
      console.log(res)
    }).catch(err => {
      console.log('get live status', err)
    })
  }

  // 监听订阅事件用于获取订阅状态
  onSubscribe(e) {
    console.log('房间号：', e.detail.room_id)
    console.log('订阅用户openid', e.detail.openid)
    console.log('是否订阅', e.detail.is_subscribe)
  }

  render () {
    // const { width, height, fontSize, color, backgroundColor, customParams, roomId } = this.state
    // @ts-ignore
    return (<subscribe
      // color={color}
      // width={width}
      // height={height}
      // roomId={roomId}
      // fontSize={fontSize}
      // customParams={customParams}
      // backgroundColor={backgroundColor}
      // bindsubscribe={this.onSubscribe.bind(this)}
    />)
  }
}
